package com.gpj.sqlbuilder.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @className ColumnType
 * @description TODO
 * @author GPJ
 * @date 2020/3/19 11:16
 * @version 1.0
 **/
@Getter
@AllArgsConstructor
public enum ColumnType {
    UUID("UUID","varchar","主键型(常用于手动设置)",36,-1),
    ID("ID","int","数字主键(常用于自增)",10,-1),
    C("C","char","定长字符型",36,-1),
    VC("VC","varchar","变长字符型",100,-1),
    N("N","numeric","浮点型",10,2),
    I("I","int","整数型",10,-1),
    DC("DC","int","字典型",2,-1),
    MONEY("MONEY","decimal","货币型",10,2),
    T("T","time","时间型",-1,-1),
    D("D","date","日期",-1,-1),
    DT("DT","timestamp","日期时间型",-1,-1),
    BLOB("BLOB","blob","二进制数据",-1,-1),
    CLOB("CLOB","text","字符数据",-1,-1);

    private final String showName;
    private final String code;
    private final String name;
    private final int defaultLength; // 默认长度
    private final int defaultAccuracy; // 默认精度

    public static ColumnType getColumnType(String code){
        for (ColumnType value : ColumnType.values()) {
            if(StringUtils.equals(value.showName, code)){
                return value;
            }
        }
        return null;
    }
}
